package com.itheima.controller;

import com.itheima.result.Result;
import com.itheima.template.OSSTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
public class FileController {

    @Autowired
    private OSSTemplate ossTemplate;

    @PostMapping("file/upload")
    public Result upload(MultipartFile uploadFile){
        try {
            String path = ossTemplate.upload(uploadFile.getOriginalFilename(), uploadFile.getInputStream());
            return Result.success(path);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("图片上传失败");
        }
    }
}
